package com.shxc.smarttrade.old.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shxc.smarttrade.R;
import com.shxc.smarttrade.old.bean.MasterDetailMsg;
import com.zhy.autolayout.utils.AutoUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by jcdev1 on 2017/5/10.
 */

public class SuperDataStaticAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    LayoutInflater mInflater;
    Context mContext;
    MasterDetailMsg.DataBean.MasterInfoBean mb;


    public SuperDataStaticAdapter(Context mContext) {
        this.mContext = mContext;
        mInflater = LayoutInflater.from(mContext);
    }

    public void setDatas(MasterDetailMsg.DataBean.MasterInfoBean mb) {
        this.mb = mb;
        notifyDataSetChanged();
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new AllPositionViewholder(mInflater.inflate(R.layout.adapter_superman_data_statis, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        if (holder instanceof AllPositionViewholder) {
            if (position == 0) {
                ((AllPositionViewholder) holder).tvOneUp.setText(mb.getWinCount() + "笔");
                ((AllPositionViewholder) holder).tvOneDown.setText("总盈利订单");
                ((AllPositionViewholder) holder).tvTwoUp.setText(mb.getLoseCount() + "笔");
                ((AllPositionViewholder) holder).tvTwoDown.setText("总亏损订单");
                ((AllPositionViewholder) holder).tvThreeUp.setText(mb.getLastMaxVolume() + "手");
                ((AllPositionViewholder) holder).tvThreeDown.setText("最大开仓");
            } else if (position == 1) {
                ((AllPositionViewholder) holder).tvOneUp.setText(mb.getWinBuyCount() + "笔");
                ((AllPositionViewholder) holder).tvOneDown.setText("成功做多交易");
                ((AllPositionViewholder) holder).tvTwoUp.setText(mb.getWinSellCount() + "笔");
                ((AllPositionViewholder) holder).tvTwoDown.setText("成功做空交易");
                ((AllPositionViewholder) holder).tvThreeUp.setText(mb.getAvgPositionTime());
                ((AllPositionViewholder) holder).tvThreeDown.setText("平均持仓时间");
            } else {
                ((AllPositionViewholder) holder).tvOneUp.setText(mb.getLastProfitRate() + "%");
                ((AllPositionViewholder) holder).tvOneDown.setText("上一日交易状况");
                ((AllPositionViewholder) holder).tvTwoUp.setText(mb.getLastWeekProfitRate() + "%");
                ((AllPositionViewholder) holder).tvTwoDown.setText("近七日交易状况");
                ((AllPositionViewholder) holder).tvThreeUp.setText(mb.getAvgMonthClose() + "笔");
                ((AllPositionViewholder) holder).tvThreeDown.setText("月平均交易笔数");
            }
        }
    }

    @Override
    public int getItemCount() {
        return mb == null ? 0 : 3;
    }

    public class AllPositionViewholder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_one_up)
        TextView tvOneUp;
        @BindView(R.id.tv_one_down)
        TextView tvOneDown;
        @BindView(R.id.tv_two_up)
        TextView tvTwoUp;
        @BindView(R.id.tv_two_down)
        TextView tvTwoDown;
        @BindView(R.id.tv_three_up)
        TextView tvThreeUp;
        @BindView(R.id.tv_three_down)
        TextView tvThreeDown;

        AllPositionViewholder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            AutoUtils.autoSize(view);
        }
    }
}
